/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2020年8月27日
 */
package com.massyframework.beanskin.util.scanning;

import java.net.URL;
import java.util.function.Predicate;

/**
 * 资源扫描器
 * 
 * <p>
 * 对指定路径下的资源的进行扫描
 * @author huangkh
 *
 */
public interface ResourceScanner<T> {

	/**
     * 判断{@code url}是否所支持的协议, 如果支持则返回所支持协议对应的资源实例
     * @param url {@link URL}
     * @return {@link T}, 不支持则返回null.
     */
    T support(URL url);
    
    /**
     * 在{@code instance}内扫描{@code resourceDir},返回所有满足{@code filter}条件的资源，
     * 
     * <p>
     * 返回值的key是针对{@code resourceDir}的相对路径，value为对应资源的URL.
     * 
     * @param instance {@link T}, 资源实例
     * @param resourceDir {@link String}, 扫描的资源目录
     * @param filter {@link Predicate},Predicate, 过滤条件
     * @param subdirectory {@link boolean}, 是否递归扫描子目录
     * @param callback {@link ResourceScanningCallback}, 资源扫描回调接口，
     * 		当发现满足<code>filter</code>条件的资源路径(针对{@code resourceDir}的相对路径)和资源定位。进行回到处理。
     */
    void scanning(T instance, String resourceDir, Predicate<String> filter,
                  boolean subdirectory, ResourceScanningCallback callback);
}
